from time import sleep
from PIL import Image
import shutil
import os

os.system("adb devices")
os.system("adb shell input tap 370 1110")

def touch():
    os.system("adb shell input tap 370 660")
    os.system("adb shell input tap 370 1110")
    os.system("adb shell input tap 370 1150")


os.system("adb exec-out screencap -p > 1.adb.0.png") ; open('1.adb.png', 'wb').write(open('1.adb.0.png', 'rb').read().replace(b'\r\n',b'\n')) # over Android 6
# os.system("adb shell screencap -p /sdcard/screenshot.png && adb pull /sdcard/screenshot.png 1.adb.png") # under Android 6
Image.open('1.adb.png').crop((0,150,720,1440)).save('1.adb.crop.png','PNG')             # Redmi6a
    
sleep(5)
shutil.copy('1.adb.crop.png', '1.last.adb.crop.png')


while True:
    os.system("adb exec-out screencap -p > 1.adb.0.png") ; open('1.adb.png', 'wb').write(open('1.adb.0.png', 'rb').read().replace(b'\r\n',b'\n')) # over Android 6
    # os.system("adb shell screencap -p /sdcard/screenshot.png && adb pull /sdcard/screenshot.png 1.adb.png") # under Android 6
    Image.open('1.adb.png').crop((0,150,720,1440)).save('1.adb.crop.png','PNG')             # Redmi6a

    if os.path.getsize('1.adb.crop.png') == os.path.getsize('1.last.adb.crop.png') :
        touch()
        
    sleep(5)
    shutil.copy('1.adb.crop.png', '1.last.adb.crop.png')


